import javax.swing.tree.TreeNode;
import java.util.LinkedList;
import java.util.Queue;
//二叉树最底层最左边的值
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public int findBottomLeftValue(TreeNode root) {
        if(root==null){
            return 0;
        }
        Queue<TreeNode> queue=new LinkedList<>();
        int tmp=0;
        queue.offer(root);
        while(!queue.isEmpty()){
            int len=queue.size();
            for(int  i=0;i<len;i++){
                TreeNode cur=queue.poll();
                if(cur.right!=null){
                    queue.offer(cur.right);
                }
                if(cur.left!=null){
                    queue.offer(cur.left);
                }
                if(i==len-1){
                   tmp=cur.val;
                }
                
            }
        }
        return tmp;

    }
}